package org.lewis.common.page;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Page<T> implements Serializable{

	private static final long serialVersionUID = 1L;

	private List<T> result = new ArrayList<T>();

	private long totalCount;

	private int page;

	private int count = 50;
	
	public Page(int page, int count) {
		this.page = page;
		this.count = count;
	}
	
	public Page(List<T> result, long totalCount, int page, int count) {
		this.result = result;
		this.totalCount = totalCount;
		this.page = page;
		this.count = count;
	}

	public List<T> getResult() {
		return result;
	}

	public void setResult(List<T> result) {
		this.result = result;
	}

	public long getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(long totalCount) {
		this.totalCount = totalCount;
	}

	public int getPage() {
		if(page<=0){
			return 1;
		}
		return page;
	}
	
	public int getP() {
		if(page<=0){
			return 1;
		}
		else if(page>=this.getTotalPages()){
			return (int) this.getTotalPages();
		}
		return page;
	}
	

	public void setPage(int page) {
		this.page = page;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	/**
	 * 获得总页数
	 * 
	 * @return
	 */
	public long getTotalPages() {
		long rows = this.totalCount;
		long mod = rows % this.count;
		if (mod == 0) {
			return rows / this.count;
		}
		return rows / this.count + 1;
	}

}
